package com.siecomzg.transport.handler;

import com.siecomzg.proto.Message;
import com.siecomzg.transport.CommonClient;

import java.util.Timer;

/**
 * Created  on 2017/2/4.
 */

public class HeartbeatHandler extends CommonHandler {
    private static Timer timer = null;

    public void cancelHeartbeat(){

        if(timer!=null){
            timer.cancel();
            timer =null;
        }
    }

//    public void startHeartbeat(final int intervalMs){
//        TimerTask task = new TimerTask() {
//            @Override
//            public void run() {
//                // task to run goes here
//                Message.siecomproto.Builder msgBuilder = Message.siecomproto.newBuilder();
//                msgBuilder.setMsgid(SiecomDevice.getUUID());
//                msgBuilder.setModule(ConstDefine.HEARTBEAT_MODULE);
//                msgBuilder.setCmd(ConstDefine.HEARTBEAT_REQUEST);
//                msgBuilder.setTimeout(intervalMs);
//                try {
//                    SiecomDevice.sendToRemote(msgBuilder.build(),"");
//                } catch (IOException e) {
//                    timer.cancel();
//
//                }
//
//            }
//        };
//        long delay = 0;
//        long intevalPeriod = intervalMs;
//        timer = new Timer();
//        // schedules the task to be run in an interval
//        timer.scheduleAtFixedRate(task, delay, intevalPeriod);
//    }

    @Override
    public void onReceive(CommonClient server, Message.siecomproto msg) {

    }
}
